#ifndef CANDEVICE_H
#define CANDEVICE_H
#include <QObject>
#include <QVector>
#include "candrive.h"
#include "canopen_sdo.h"


struct Frame
{
    uint32_t id;      // 帧ID
    uint8_t data[8]; // 数据字段
    uint8_t dlc;     // 数据长度码
};

struct Param
{
    //电源板
    QString current;
    QString vol;
    QString soc;
    QString temprature;
    QString bms_status;
    QString bms_fault;
    QString acc_key;
    QString emergency_pmu;
    QString left_detect;
    QString right_detect;
    QString handle_detect;

    //清洁业务版
    QString bud_status;
    QString left_brush ;
    QString right_brush;
    QString waterpush;
    QString brushpush;
    QString suction ;
    QString spraygear;
    QString clean_drain;
    QString dirty_drain ;
    QString topledflash;
    QString frontled;
    QString clean;
    QString dirty;
    QString clean_empty;
    QString dirty_full;
    //人机板
    QString hou_status;
    QString set_speed;
    QString speaker;
    QString front_led_key;
    QString crash;
    QString clean_start_key;
    QString suction_start_key;
    QString pressure;
    QString epf;
    QString pause_key;
    QString front_key;
    QString back_key;
    QString nfc;
    QString slope_angel;
    //运动控制板
    QString emergency_wdu ;
    QString run_motor_type;
    QString run_motor_status;
    QString run_motor_speed;
    QString run_motor_error;
    QString steer_motor_error;
    QString steer_angle;
};


class CanDevice:public QObject
{
    Q_OBJECT
public:
    CanDevice();
    bool connetStatus ;
    bool ConnetCAN(void);
    bool CloseCAN(void);
    void printCANFrame(const Frame& frame);
    void canFrameProcess(Frame frame);
    Frame frame[1024];
    Param param ;

    uint64_t uint8ArrayToUint64( uint8_t *array);
    float getSignalFromFrame(Frame frame, int16_t StartBit, int16_t BitLength, float Factor, int16_t Offset);
    int32_t canTransmitData(uint32_t id ,uint8_t len , uint8_t *buf);

public slots:
    void canRecvData(void);
    void canSendData(void);

signals:
    void updateSignal(Param *param);
    void updateParam(OdParam *odParam);

private:
    CanDrive * canDrive;
    CanOpenSdo *canopensdo;

};
#endif // CANDEVICE_H
